/**
 * @Author: liguigong liguigong@shopline.com
 * @Date: 2025-09-23 09:41:10
 * @LastEditors: liguigong liguigong@shopline.com
 * @LastEditTime: 2025-10-13 14:30:53
 * @FilePath: sheep/api/fittingRoom/index.js
 * @Description: 这是默认设置,可以在设置》工具》File Description中进行配置
 */
import request, { getAccessToken } from '@/sheep/request';
import { apiPath, baseUrl, tenantId } from '../../config';

const FittingRoomApi = {
  getClothList: (data) => {
    return request({
      url: '/cloth/list',
      method: 'POST',
      data: data,
      custom: {
        showLoading: false,
      },
    });
  },
  // 上传模特
  uploadModel: (file, formData = {}) => {
    uni.showLoading({
      title: '上传中',
    });
    return new Promise((resolve, reject) => {
      uni.uploadFile({
        url: baseUrl + apiPath + '/cloth/uploadModel',
        filePath: file,
        name: 'file',
        header: {
          Accept: '*/*',
          Authorization: getAccessToken(),
        },
        formData,
        success: (uploadFileRes) => {
          console.log('🚀 ~ success 🐶43 ~ uploadFileRes: ', uploadFileRes);
          let result = JSON.parse(uploadFileRes.data);
          if (result.error === 1) {
            uni.showToast({
              icon: 'none',
              title: result.msg,
            });
          } else {
            return resolve(result);
          }
        },
        fail: (error) => {
          console.log('上传失败：', error);
          return resolve(false);
        },
        complete: () => {
          uni.hideLoading();
        },
      });
    });
  },
  // 上传模特
  uploadCloth: (file, formData = {}) => {
    uni.showLoading({
      title: '上传中',
    });
    return new Promise((resolve, reject) => {
      uni.uploadFile({
        url: baseUrl + apiPath + '/cloth/uploadClothFile',
        filePath: file,
        name: 'file',
        header: {
          Accept: '*/*',
          Authorization: getAccessToken(),
        },
        formData,
        success: (uploadFileRes) => {
          console.log('🚀 ~ success 🐶43 ~ uploadFileRes: ', uploadFileRes);
          let result = JSON.parse(uploadFileRes.data);
          if (result.error === 1) {
            uni.showToast({
              icon: 'none',
              title: result.msg,
            });
          } else {
            return resolve(result);
          }
        },
        fail: (error) => {
          console.log('上传失败：', error);
          return resolve(false);
        },
        complete: () => {
          uni.hideLoading();
        },
      });
    });
  },

  getModelList: (data) => {
    return request({
      url: '/cloth/getModelList',
      method: 'POST',
      data: data,
    });
  },
  // 得到分类
  getCategory: () => {
    return request({
      url: '/product/category/tree',
      method: 'GET',
    });
  },

  // 获取试穿结果
  getTestResults: (data) => {
    return request({
      url: '/digital/on-record/page',
      method: 'GET',
      params: data,
      custom: {
        showLoading: false,
      },
    });
  },

  // 上传或者编辑衣服
  uploadAndEditCloth: (data) => {
    return request({
      url: '/cloth/uploadCloth',
      method: 'POST',
      data: data,
    });
  },

  // 删除衣服
  deleteCloth: (data) => {
    return request({
      url: '/cloth/deleteCloth',
      method: 'POST',
      data: data,
    });
  },
  //试穿
  tryOnApi: (data) => {
    return request({
      url: '/digital/on-record/create',
      method: 'POST',
      data: data,
    });
  },

  //发型试穿
  hairstyleTryOnApi: (data) => {
    return request({
      url: '/digital/on-record/exchange-hair',
      method: 'POST',
      data: data,
    });
  },

  addHairApi: (data) => {
    return request({
      url: '/userinfo/add_hair_data',
      method: 'POST',
      data: data,
    });
  },
  getStyleApi: (data) => {
    return request({
      url: '/userinfo/get_user_face_info',
      method: 'POST',
      data: data,
    });
  },
  praiseTextApi: (data) => {
    return request({
      url: '/ai/praiseTexttwo',
      method: 'POST',
      data: data,
    });
  },
  wardrobeListApi: (data) => {
    return request({
      url: '/wardrobe/clothes_list',
      method: 'POST',
      data: data,
    });
  },
  exchangeHairApi: (data) => {
    return request({
      url: '/api/v1/test/exchangeHair',
      method: 'POST',
      data: data,
    });
  },
  exchangeHairHistoryByTaskId: (data) => {
    return request({
      url: '/api/v1/test/exchangeHairHistoryByTaskId',
      method: 'POST',
      data: data,
    });
  },
  hairStyleListApi: (data) => {
    return request({
      url: '/api/v1/test/getHairDetails',
      method: 'POST',
      data: data,
    });
  },
};
export default FittingRoomApi;
